package com.lr.falsework.common.bean;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ws.commons.tool.StrTool;

public class PageBean {
    private Integer page;
    private Integer limit=20;
	public Integer getPage() {
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}
	public Integer getLimit() { 
		return limit;
	}
	public void setLimit(Integer limit) {
		this.limit = limit;
	}
	
	
   public   void startIfPageIng() {
	   if(page!=null) {
		   PageHelper.startPage(page,limit);
	   }
   }
   
   public static Object toMapIfPage(Object data){
	   if(data instanceof Page<?>) {
		   Page<?> pg=(Page<?>)data;
		   Map<String,Object> map=new HashMap<>();
		   map.put("list",pg.getResult());
		   map.put("total",pg.getTotal());
		   map.put("page",pg.getPageNum());
		   map.put("limit",pg.getPageSize());
		   return map;
	   }
	   return data;
   }
}
